package com.spring.boot.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.spring.boot.entity.Contract;
import com.spring.boot.entity.InsurancePolicy;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Daniel ZTQ
 * @Date: 2021/01/01 12:13
 * @Description: TODO
 */
@Service
public interface InsurancePolicyMapper extends BaseMapper<InsurancePolicy> {

    /**
     * 根据合同查询保单信息
     * */
    @Select("select * from insurance_policy where contract_Id=#{contractId}")
    List<InsurancePolicy> getInsurancePolicyByContractId(@Param("contractId")String contractId);

    /**
     * 根据被保险人id 查询保单信息
     * */
    @Select("select * from insurance_policy where insured_id=#{insuredId}")
    List<InsurancePolicy> getInsurancePolicyByInsuredId(@Param("insuredId") Integer insuredId);

    /**
     * 根据身份证号查询保单信息
     * */
    @Select("select * from insurance_policy where insured_id_card=#{insuredIdCard}")
    List<InsurancePolicy> getInsurancePolicyByinsuredIdCard(@Param("insuredIdCard") String insuredIdCard);

    /**
     * 查询所有保单sql
     * */
    @Select("select * from insurance_policy")
    List<InsurancePolicy> getInsurancePolicyAll();

    /**
     * 查询所有保单sql
     * */
    @Select("select * from insurance_policy where state=#{state}")
    List<InsurancePolicy> getInsurancePolicyAllAndState(@Param("state") String state);
    /**
     * 发起理赔sql
     */
    @Update("update insurance_policy set state='2' where Insurance_policy_uuid=#{insurancePolicyUuid}")
    int updateInsurancePolicyState(@Param("insurancePolicyUuid")String insurancePolicyUuid);

    /**
     * 财务人员进行理赔sql
     */
    @Update("update insurance_policy set state='3' where Insurance_policy_uuid=#{insurancePolicyUuid}")
    int settlementOfClaims(@Param("insurancePolicyUuid")String insurancePolicyUuid);

    /**
     * 根据身份证号查询保单信息
     * */
    @Select("select * from insurance_policy where insurance_policy_uuid=#{insurancePolicyUuid}")
    InsurancePolicy getInsurancePolicy(@Param("insurancePolicyUuid") String insurancePolicyUuid);

    /**
     * 修改保单状态为已过期
     * */
    @Update("update insurance_policy set state='4' where contract_id=#{contractId}")
    int updateSynchronizationState(@Param("contractId")String contractId);

    @Select("SELECT insurance_policy.* from insurance_policy JOIN (select id from insured JOIN  (SELECT uid from user where id_card=#{idCard}) a  on  insured.uid=a.uid)b on insurance_policy.insured_id=b.id")
    List<InsurancePolicy> getInsurancePolicyByIdCard(@Param("idCard") String idCard);

    @Select("select * from insurance_policy where state=#{state} and insured_id_card=#{insuredIdCard}")
    List<InsurancePolicy> getInsurancePolicyByUidAndState(@Param("state") String state,@Param("insuredIdCard") String insuredIdCard);
}
